/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.controller;

import br.siagefi.model.ClientePJ;
import br.siagefi.service.ClientePJService;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Paulo Lavarini
 */
@SessionScoped
@ManagedBean
public class ClientePJBean implements Serializable{
    private ClientePJ clientePJ;
    private final ClientePJService service;
    private List<ClientePJ> clientesPJ;

    public ClientePJBean() {
        this.clientePJ = new ClientePJ();
        this.service = new ClientePJService();
        this.carregarLista();
    }
    
     public final void carregarLista(){
         this.clientesPJ = service.listar();
    }
    
    public String gravar(){
        service.gravar(this.getClientePJ());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "clientePJ?faces-redirect=true";
    }
    
    public String alterar(ClientePJ clientePJ){
        this.setClientePJ(clientePJ);
        return "incluirClientePJ";
    }
    
     public String remover(){
        service.remover(this.getClientePJ());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "clientePJ";
    }
     
    public String remover(ClientePJ clientePJ){
        service.remover(clientePJ);
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "clientePJ";
    }
  
    public void limparFormularioDoJsf(){
        this.clientePJ = new ClientePJ();
    }

    public ClientePJ getClientePJ() {
        return clientePJ;
    }

    public void setClientePJ(ClientePJ clientePJ) {
        this.clientePJ = clientePJ;
    }

    public List<ClientePJ> getClientesPJ() {
        return clientesPJ;
    }

    public void setClientePJs(List<ClientePJ> clientesPJ) {
        this.clientesPJ = clientesPJ;
    }
}
